{% extends "base.html" %}

{% block nav %}
<li class="active">
    <i class="fa fa-sitemap fa-fw"></i> 修改主机
</li>
{% endblock %}

{% block css %}
	<style type="text/css">
		#host_from div {
			padding-top: 10px;
		}
	</style>

{% endblock %}

{% block content %}
	<div class="col-lg-12">
		<div id='message'  style="display:none;">
			出问题了
		</div>

		<div class="col-lg-12">
			<div class='panel panel-primary'>

				<div class='panel-heading'>修改主机</div>
				    <div class="panel panel-body">
	                  	<form id="hostForm"  class="form-horizontal" action="/cmdb/edit/save" method="post">

				<div class='panel-heading'>添加主机</div>
				<div class="panel panel-body">
	                  	<form id="hostForm"  class="form-horizontal" action="/cmdb/edit/host" method="post">

			                <div class="form-group">
                                <input class="form-control" name='id' placeholder="id" value="{{ host_info[0] }}" hidden>
							    <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">固定资产编号：</div>
							      <input class="form-control" name='assets_number' placeholder="assets_number" value="{{ host_info[1] }}">
							    </div>
							    <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">IDC类型：</div>
							      <input class="form-control" name='IDC_type' placeholder="IDC_type" value="{{ host_info[2] }}">
							    </div>
							    <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">机房信息：</div>
							      <input class="form-control" name='room_info' placeholder="room_info" value="{{ host_info[3] }}">
							    </div>
							    <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">机柜信息：</div>
							      <input class="form-control" name='cabinet_info' placeholder="cabinet_info" value="{{ host_info[4] }}">
							    </div>
							    <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">系列号：</div>
							      <input class="form-control" name='serial_number' placeholder="serial_number" value="{{ host_info[5] }}">
							    </div>
							    <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">型号：</div>
							      <input class="form-control" name='model_number' placeholder="model_number" value="{{ host_info[6] }}">
							    </div>
							    <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">外网IP：</div>
							      <input class="form-control" name='wan_ip' placeholder="wan_ip" value="{{ host_info[7] }}">
							    </div>
							    <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">内网IP：</div>
							      <input class="form-control" name='ip' placeholder="ip" value="{{ host_info[8] }}">
							    </div>
							    <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">远程管理卡IP：</div>
							      <input class="form-control" name='remote_ip' placeholder="remote_ip" value="{{ host_info[9] }}">
							    </div>
							    <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">状态：</div>
							      <input class="form-control" name='status' placeholder="status" value="{{ host_info[10] }}">
							    </div>
							    <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">使用方：</div>
							      <input class="form-control" name='assets_user' placeholder="assets_user" value="{{ host_info[11] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">业务名称：</div>
							      <input class="form-control" name='business_type' placeholder="business_type" value="{{ host_info[12] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">业务类型：</div>
							      <input class="form-control" name='business_name' placeholder="business_name" value="{{ host_info[13] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">详细作用：</div>
							      <input class="form-control" name='detailed_action' placeholder="detailed_action" value="{{ host_info[14] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">上线时间：</div>
							      <input class="form-control" name='upline_time' placeholder="upline_time" value="{{ host_info[15] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">下线时间：</div>
							      <input class="form-control" name='downline_time' placeholder="downline_time" value="{{ host_info[16] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">操作系统：</div>
							      <input class="form-control" name='osystem' placeholder="osystem" value="{{ host_info[17] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">来源：</div>
							      <input class="form-control" name='source' placeholder="source" value="{{ host_info[18] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">租售期限：</div>
							      <input class="form-control" name='deadline' placeholder="deadline" value="{{ host_info[19] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">合同单号：</div>
							      <input class="form-control" name='contract_number' placeholder="contract_number" value="{{ host_info[20] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">单价：</div>
							      <input class="form-control" name='price' placeholder="price" value="{{ host_info[21] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">月度费用：</div>
							      <input class="form-control" name='monthly_fee' placeholder="monthly_fee" value="{{ host_info[22] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">上架时间：</div>
							      <input class="form-control" name='up_time' placeholder="up_time" value="{{ host_info[23] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">下架时间：</div>
							      <input class="form-control" name='down_time' placeholder="down_time" value="{{ host_info[24] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">使用天数：</div>
							      <input class="form-control" name='usage_days' placeholder="usage_days" value="{{ host_info[25] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">本月计费：</div>
							      <input class="form-control" name='monthbilling' placeholder="monthbilling" value="{{ host_info[26] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">备注信息：</div>
							      <input class="form-control" name='comment' placeholder="comment" value="{{ host_info[27] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">应用信息：</div>
							      <input class="form-control" name='application' placeholder="application" value="{{ host_info[28] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">port：</div>
							      <input class="form-control" name='port' placeholder="port" value="{{ host_info[29] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">username：</div>
							      <input class="form-control" name='username' placeholder="username" value="{{ host_info[30] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">password：</div>
							      <input class="form-control" name='password' placeholder="password" value="{{ host_info[31] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">CPU：</div>
							      <input class="form-control" name='cpu' placeholder="CPU" value="{{ host_info[32] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">Mem：</div>
							      <input class="form-control" name='mem' placeholder="Mem" value="{{ host_info[33] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">Disk：</div>
							      <input class="form-control" name='disk' placeholder="Disk" value="{{ host_info[34] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">带宽：</div>
							      <input class="form-control" name='bandwidth' placeholder="bandwidth" value="{{ host_info[35] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">Room_id：</div>
							      <input class="form-control" name='Room_id' placeholder="Room_id" value="{{ host_info[36] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">Cabinet_id：</div>
							      <input class="form-control" name='Cabinet_id' placeholder="Cabinet_id" value="{{ host_info[37] }}">
							    </div>
                                <div class="input-group" style="width: 300px;padding-left:25px;">
							      <div class="input-group-addon">机位信息：</div>
							      <input class="form-control" name='location' placeholder="location" value="{{ host_info[38] }}">
							    </div>
							    <div style="padding-right:300px;padding-left:25px;padding-top:25px";>
                                 <button class="btn btn-info btn-sm">保存</button>
							    </div>
							</div>
	                	</form>
	                </div>
				</div>
			</div>
		</div>
	</div>

{% endblock %}

{% block js %}
	<script type="text/javascript">
			//表单提交函数
			function commitForm(url,postValue){
				$.post(url,
					   postValue,
					   function(data){
					   		//正确处理
						    if(data.code === 0){
						    	//类样式修改成红色
								$('#message').removeClass().addClass('alert alert-success');
							}
							//错误处理
							else{
								//类样式修改成红色
								$('#message').removeClass().addClass('alert alert-danger');
							}
							//显示message默认是不显示，这里显示
							$('#message').text(data.message);
							$('#message').show();
							setTimeout(function(){
								$('#message').removeClass();
								$('#message').hide();

							},3000);
					   });
			};

			$(document).ready(function(){
				//添加机房
				$('#roomButton').click(function(e) {
					// 获取值转义
					var postValue = $('#roomForm').serialize();
					// 禁止submit按钮生效
					e.preventDefault();
					commitForm('/cmdb/add/room',postValue)
				});

				//添加机柜
				$('#cabinetButton').click(function(e) {
					// 获取值转义
					var postValue = $('#cabinetForm').serialize();
					// 禁止submit按钮生效
					e.preventDefault();
					commitForm('/cmdb/add/cabinet',postValue)
				});

				//添加主机
				$('#hostButton').click(function(e) {
					// 获取值转义
					var postValue = $('#hostForm').serialize();
					// 禁止submit按钮生效
					e.preventDefault();
					commitForm('/cmdb/add/host',postValue)
				});
			});
	</script>
{% endblock %}